package com.example.uploadimage.config;

import com.example.uploadimage.constant.UploadImagePath;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@Configuration
public class MyWebConfig extends WebMvcConfigurationSupport {


	//对静态资源的配置
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {

		String os = System.getProperty("os.name"); // 判断操作系统

		if (os.toLowerCase().startsWith("win")) {  //如果是Windows系统
			registry.addResourceHandler("/images/**")
					// /apple/**表示在磁盘apple目录下的所有资源会被解析为以下的路径
					.addResourceLocations("file:" + UploadImagePath.WindowPrefixPath); //媒体资源,实际的访问的本地路径。
			registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");

		} else {  //linux 和mac
			registry.addResourceHandler("/images/**")
					.addResourceLocations("file:" + UploadImagePath.LinuxPrefixPath)   //媒体资源
					.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");  //swagger2页面;
		}
	}
}